﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups.fountain {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.events.*;
    import flash.display.*;
    import reprise.controls.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.popups.*;
    import net.wooga.pets.views.components.*;
    import net.wooga.pets.events.windows.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class AbstractFountainPopupMediator extends AbstractPopupMediator {

        public var ticker:TickModel;
        protected var _content:UIComponent;
        protected var _rewardContent:UIComponent;
        protected var _actionButton:LabelButton;
        protected var _fountainData:Object;
        protected var _gemContainer:FountainGemContainer;
        protected var _rewardCount:int;

        private static const ICON_WIDTH:Number = 50;
        private static const ITEMCONTAINER_WIDTH:Number = 100;

        override public function onRegister():void{
            super.onRegister();
            this._fountainData = this.view.data;
            this.createContentContainer();
            this.createRewardContainer();
            this.createGemContainer();
            this.addFountainHeader("fountain_title", this._content);
            var _local1:String = this.view.data.speaker;
            this.addSpeaker(_local1, this._content);
        }
        protected function addReward(_arg1:String, _arg2:int, _arg3:UIComponent=null):void{
            var type = _arg1;
            var count = _arg2;
            var container = _arg3;
            var rewardContainer:UIComponent = RepriseUtils.addComponent(((container) || (this.view)), "rewardContainer");
            rewardContainer.setStyle("width", ITEMCONTAINER_WIDTH.toString());
            var icon:UIComponent = this.addLabelIcon((type + "Icon icon"), rewardContainer);
            RepriseUtils.validateComponent(icon, function (_arg1:UIComponent):void{
                Displays.correctScaling(_arg1, _arg1, ICON_WIDTH, ICON_WIDTH, 0, 0);
                var _local2:int = ((ITEMCONTAINER_WIDTH / 2) - ((_arg1.borderBoxWidth * _arg1.scaleX) / 2));
            });
            var text:String = language.getTextByKey(("global_amount_" + type), {amount:count});
            var label:Label = RepriseUtils.addLabel(rewardContainer, "rewardText myriadProFontNormal", text, null);
            label.addEventListener(DisplayEvent.VALIDATION_COMPLETE, this.onLabelValidated);
        }
        private function onLabelValidated(_arg1:DisplayEvent):void{
            var _local2:Label = (_arg1.target as Label);
            _local2.removeEventListener(DisplayEvent.VALIDATION_COMPLETE, this.onLabelValidated);
            var _local3:int = (((ICON_WIDTH / 2) - ((_local2.borderBoxWidth * _local2.scaleX) / 2)) * 1);
            _local2.setStyle("left", _local3.toString());
        }
        protected function addLabelIcon(_arg1:String, _arg2:UIComponent=null):UIComponent{
            return (RepriseUtils.addComponent(((_arg2) || (this.view)), _arg1));
        }
        protected function addActionButton(_arg1:String, _arg2:UIComponent=null, _arg3:Function=null):void{
            this._actionButton = createButton(((_arg2) || (this.view)), "greenButton", _arg1, "myriadProFont");
            eventMap.mapListener(this._actionButton, MouseEvent.CLICK, ((_arg3) || (this.onClick)));
        }
        protected function addPodest(_arg1:UIComponent=null):UIComponent{
            var target = _arg1;
            var podestPet:String = ((this.view.data.podest) || (this.view.data.speaker));
            var clip:MovieClip = AssetsLibrary.getMovieClip(podestPet);
            clip.filters = [Filters.getFilter(Filters.SENIOR_GLOW)];
            var podestContainer:UIComponent = RepriseUtils.addComponent(((target) || (this._content)), "podestContainer");
            var icon:UIComponent = RepriseUtils.addClipComponent(podestContainer, "podestPet", clip);
            RepriseUtils.validateComponent(icon, function (_arg1:ClipComponent):void{
                Displays.correctScaling(_arg1, _arg1.clip, _arg1.width, _arg1.height, -1, 0);
            });
            return (podestContainer);
        }
        protected function addSpeaker(_arg1:String, _arg2:UIComponent=null):void{
            var speaker = _arg1;
            var target = _arg2;
            var clip:MovieClip = AssetsLibrary.getMovieClip(speaker);
            var speakerContainer:UIComponent = RepriseUtils.addComponent(((target) || (this._content)), "speakerContainer");
            var speakerClip:UIComponent = RepriseUtils.addClipComponent(speakerContainer, "speaker", clip);
            RepriseUtils.validateComponent(speakerClip, function (_arg1:ClipComponent):void{
                Displays.correctScaling(_arg1, _arg1.clip, _arg1.width, _arg1.height, 0, 0);
            });
        }
        protected function addFountainSubHeader(_arg1:String, _arg2:Object=null, _arg3:UIComponent=null):void{
            addLabel("fountainSubHeader myriadProFontNormal", _arg1, _arg2, ((_arg3) || (this.view)));
        }
        private function addFountainHeader(_arg1:String, _arg2:UIComponent=null):void{
            addLabel("fountainHeader showcardGothicFontOutline", _arg1, null, ((_arg2) || (this.view)));
        }
        protected function adjustRewardContentWidth(_arg1:int):void{
            var _local2:int = (_arg1 * GameConstants.FOUNTAIN_REWARD_CONTAINER_WIDTH);
            this._rewardContent.setStyle("width", _local2.toString());
        }
        protected function onClick(_arg1:MouseEvent):void{
            _arg1.stopPropagation();
            this.close();
        }
        protected function onCancel(_arg1:MouseEvent):void{
            _arg1.stopPropagation();
            this.close();
        }
        override protected function close():void{
            super.close();
            dispatch(new Event(EventConstants.REACTIVATE_FOUNTAIN_ACTIONS));
            this.ticker.pause = false;
            var _local1:WindowCommandTriggerEvent = new WindowCommandTriggerEvent(WindowCommandTriggerEvent.DESTROY_STANDARD_WINDOW);
            var _local2:Event = new Event(EventConstants.FOUNTAIN_CLOSED);
            dispatch(_local2);
        }
        private function createGemContainer():void{
            this._gemContainer = new FountainGemContainer();
            this.view.addChild(this._gemContainer);
        }
        private function createContentContainer():void{
            this._content = RepriseUtils.addComponent(this.view, "fountainContent");
        }
        private function createRewardContainer():void{
            this._rewardContent = RepriseUtils.addComponent(this.view, "rewardContent");
        }
        private function get view():AbstractFountainPopupView{
            return ((viewComponent as AbstractFountainPopupView));
        }

    }
}//package net.wooga.pets.views.popups.fountain 
